package Test2;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;

public class MyJFrame1 extends JFrame implements ActionListener {
    JButton jtb1 = new JButton("登录");
    JButton jtb2 = new JButton("登录");
    public MyJFrame1() {
        this.setSize(600, 800);
        this.setTitle("登录");
        this.setAlwaysOnTop(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setLocationRelativeTo(null);
        this.setLayout(null);


        jtb1.setBounds(0, 0, 100, 50);
        jtb1.addActionListener(this);
        //添加按钮到窗体中
        this.add(jtb1);

        jtb2.setBounds(100, 0, 100, 50);
        jtb2.addActionListener(this);
        this.add(jtb2);

        this.setVisible(true);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        //获取当前被操作的那个按钮对象
        Object obj = e.getSource();
        if(obj == jtb1)
        {
            jtb1.setSize(200,200);
        }
        else if(obj == jtb2)
        {
            Random r = new Random();
            jtb2.setLocation(r.nextInt(500),r.nextInt(500));
        }
    }
}
